﻿using System;

using System.Collections.Generic;
using System.Text;

namespace Silvermoon.Controls.Sys
{
    /// <summary>
    /// Control to contain the items inside a lens. See also <seealso cref="T:LensView"/>.
    /// </summary>
    internal class LensItemsContainer : Panel, IScrollEventBehavior, IMouseEventBehavior
    {
        private LensView view;
        int startOffset;

        public LensItemsContainer(LensView lensView)
            : base()
        {
            view = lensView;
        }

        #region IScrollEventBehavior Members

        bool scroll;

        public void OnScroll(ScrollEventArgs e)
        {
            if (!e.Handled && scroll)
            {
                e.Handled = true;
                if (!e.IsMouseDown) e.Cancel = true;
                int top = e.Position.Y - e.StartPosition.Y + startOffset;
                view.LensOffset = top;
            }
        }

        public void OnBeginScrollData(BeginScrollEventArgs e)
        {
            scroll = e.Ay > (e.Ax * 2 / 3);
            e.Handled = true;
        }

        public void OnEndScrollData(EndScrollEventArgs e)
        {
        }

        #endregion

        #region IMouseEventBehavior Members

        public virtual void OnMouseDown(MouseDownEventArgs e)
        {
            startOffset = view.LensOffset;
        }

        public virtual void OnMouseUp(MouseUpEventArgs e)
        {

        }

        public virtual void OnMouseClick(MouseClickEventArgs e)
        {

        }

        public virtual void OnMouseMove(MouseMoveEventArgs e)
        {
        }

        public virtual void OnGotFocus()
        {
        }

        public virtual void OnLostFocus()
        {
        }

        public virtual bool IsFocused
        {
            get { return false; }
        }

        #endregion
    }
}
